﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AppSocketModel;
using AppSocketService.Product;
using BCGPSCommon;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BCGPSRESTful.Controllers.Page.Product
{
    /// <summary>
    /// 产品
    /// </summary>
    [ApiExplorerSettings(GroupName = "SystemAccount")]
    [Route("api/[controller]")]
    [ApiController]
    public class ProductController : PageBaseController
    {
        private readonly IProductService productService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productService"></param>
        public ProductController(IProductService productService)
        {
            this.productService = productService;
        }

        #region 批量添加
        /// <summary>
        /// 批量添加产品
        /// </summary>
        /// <param name="requestDto"></param>
        /// <returns></returns>
        [HttpPost("[action]")]
        [ProducesResponseType(typeof(int), 200)]
        public int AddList([FromBody]ProductRequestDto requestDto)
        {
            return productService.Add(requestDto);
        }
        #endregion

        #region 修改基础信息
        /// <summary>
        /// 修改基础信息
        /// </summary>
        /// <param name="productDto"></param>
        /// <returns></returns>
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(ProductDto), 200)]
        public ProductDto UpdateBaseInfo(ProductDto productDto)
        {
            return productService.UpdateBaseInfo(productDto);
        }
        #endregion

        #region 修改销售信息
        /// <summary>
        /// 修改销售信息
        /// </summary>
        /// <param name="productBuyInfoDto"></param>
        /// <returns></returns>
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(ProductDto), 200)]
        public int UpdateBuyInfo(ProductBuyInfoDto  productBuyInfoDto)
        {
            return productService.UpdateBuyInfo(productBuyInfoDto);
        }
        #endregion

        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns> 
        [HttpDelete("{imei}")]
        [ProducesResponseType(typeof(long), 200)]
        public long Delete(string imei)
        {
            return productService.Delete(imei);
        }
        #endregion

        #region 批量删除
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="imei_list"></param>
        /// <returns></returns>
        [HttpDelete("[action]")]
        [ProducesResponseType(typeof(long), 200)]
        public long DeleteList([FromBody]List<string> imei_list)
        {
            return productService.DeleteList(imei_list);
        }
        #endregion

        #region 获取全部产品  -- 分页
        /// <summary>
        /// 获取全部用户 -- 分页
        /// </summary>
        /// <param name="deviceType">设备类型</param>
        /// <param name="lifeStatus">生命周期状态</param>
        /// <param name="model">型号</param>
        /// <param name="account_code">账户号</param>
        /// <param name="imei"></param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="desc">倒序</param>
        /// <param name="index">页码</param>
        /// <param name="size">记录数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<ProductDto>), 200)]
        public PageableList<ProductDto> Query(
            [FromQuery(Name = "device_type")]DeviceType? deviceType,
            [FromQuery(Name = "life_status")]LifeStatus?   lifeStatus,
            string model,
            string account_code,
            string imei, 
            DateTime?  start, DateTime? end, bool? desc = false, int? index = 0, int? size = 20)
        {
            return productService.GetList(deviceType, lifeStatus, model, account_code, imei, start, end, desc.Value, index.Value, size.Value);
        }
        #endregion
    }
}